package com.slimbloody.warmup;

import com.slimbloody.hbase.HBaseRowKeyEnum;
import com.slimbloody.infra.warmup.WarmUp;
import com.ysb.hbase.dml.HbaseDmlService;
import com.ysb.hbase.model.HbaseGetParam;
import com.ysb.hbase.model.ValueModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

@Component
@Slf4j
public class HBaseWarmUp implements WarmUp {
  @Autowired
  private HbaseDmlService hbaseDmlService;
  public static final String rowKey = "123";

  @Override
  public boolean warm() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start("get");
    try {
      ValueModel value = hbaseDmlService.getValue(
        new HbaseGetParam(
          HBaseRowKeyEnum.UserTcmQualityFeature.getTable(),
          HBaseRowKeyEnum.UserTcmQualityFeature.getCf(),
          rowKey,
          HBaseRowKeyEnum.UserTcmQualityFeature.getQualifier()
        )
      );
      log.info("hbase warmup value: {}", value);
    } catch (Exception e) {
      log.warn("warmup failed: e");
    } finally {
      stopWatch.stop();
    }
    log.info("hbase warmup cost: {}ns", stopWatch.getLastTaskInfo().getTimeNanos());
    return true;
  }
}
